//
//  ContributionListViewController.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/3/26.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "ContributionListViewController.h"
#import "OrderNewsCollectionViewCell2.h"
#import "ContributionLogic.h"
#import "UserInfoViewController.h"
@interface ContributionListViewController ()<ContributionLogicDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
@property(nonatomic, strong)  ContributionLogic *logic;
@end

@implementation ContributionListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化逻辑类
    
    self.title  = ASLocalizedString(@"贡献榜");
    _logic = [ContributionLogic new];
    _logic.delegagte = self;
    _logic.touid = _touid;
    [_logic loadData];
    [self setupUI];
}

#pragma mark ————— 初始化页面 —————
-(void)setupUI{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    self.collectionView.collectionViewLayout = layout;
    layout.minimumLineSpacing = 1;//设置最小行间距
    layout.minimumInteritemSpacing = 1;//item间距(最小值)
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);//设置section的编距
    
    self.collectionView.backgroundColor = CViewBgColor;
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([OrderNewsCollectionViewCell2 class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([OrderNewsCollectionViewCell2 class])];
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([OrderNewsCollectionViewCell2 class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([OrderNewsCollectionViewCell2 class])];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.view addSubview:self.collectionView];
    
    
}

#pragma mark ————— 下拉刷新 —————
-(void)headerRereshing{
    _logic.page = 1;
    [_logic loadData];
    [self removeNoDataImage];
    
}

#pragma mark ————— 上拉刷新 —————
-(void)footerRereshing{
    _logic.page+=1;
    [_logic loadData];
    [self removeNoDataImage];
}

#pragma mark ————— 数据拉取完成 渲染页面 —————
-(void)requestDataCompleted{
    [self.collectionView.mj_footer endRefreshing];
    [self.collectionView.mj_header endRefreshing];
    
    [UIView performWithoutAnimation:^{
        [self.collectionView reloadData];
    }];
    
}

#pragma mark ————— collection代理方法 —————
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _logic.dataArray.count;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    OrderNewsCollectionViewCell2 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([OrderNewsCollectionViewCell2 class]) forIndexPath:indexPath];
    cell.backgroundColor = CF6;
    //        cell.type = self.type;
    
    [cell setModel:_logic.dataArray[indexPath.row]];
//    cell.model = _logic.dataArray[indexPath.row];
    return cell;
}

//*******重写的时候需要走一句话
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    OrderModel *model;
    model = _logic.dataArray[indexPath.row];
    UserInfoViewController *user = [UserInfoViewController new];
    user.uid = model.id;

    [self.navigationController pushViewController:user animated:NO];
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    if (section == 0 )
    {
        return UIEdgeInsetsMake(0, 0, 0, 0);
    }
    
    return UIEdgeInsetsMake(0, 0, 0, 0);
}


- (CGSize)collectionView:(nonnull UICollectionView *)collectionView layout:(nonnull UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
    return CGSizeMake(SCREEN_WIDTH,60);
}




-(void)requestShuffingCompleted:(NSArray *)model
{

}
#pragma mark ————— 转场动画起始View —————
-(UIView *)targetTransitionView{
    return self.view;//专场动画
}

-(BOOL)isNeedTransition{
    return YES;
}


-(void)naviBtnClick:(UIButton *)btn{
    DLog(ASLocalizedString(@"点击了筛选按钮"));
}

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
    self.collectionView.frame = CGRectMake(0, 0, KScreenWidth, SCREEN_HEIGHT);
    
}

-(void)switchType:(NSString *)type
{
    [self headerRereshing];
}

#pragma mark -  上下滑动隐藏/显示导航栏

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
